﻿using Quartz;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WeChartWorkRobot.Model;
using WeChartWorkRobot.Model.DTO;
using WeChartWorkRobot.Service;
using WeChartWorkRobot.Service.CustomerMsg;
using WeChartWorkRobot.Service.Jobs;

namespace WeChartWorkRobot.Service
{
    public class SendCustomerMsgJob : Jobs.IJob
    {
        public void Execute(ExecuteContext context)
        {
            Console.WriteLine("SendCustomerMsgJob任务执行");
            LogHelper.Debug("SendCustomerMsgJob任务执行");

            CustomerWxMsg wxMsg = (CustomerWxMsg)context.GetData("wxMsg");

            string strClassFullName = $"WeChartWorkRobot.Service.CustomerMsg.{wxMsg.class_name}";//完整类名
            var assembly = Assembly.GetExecutingAssembly();
            Type dllType = assembly.GetType(strClassFullName);//加载类
            SendCustomerMsgBase obj = (SendCustomerMsgBase)Activator.CreateInstance(dllType);
            wxMsg.content = obj.getContent();

            if (string.IsNullOrEmpty(wxMsg.content))
            {
                LogHelper.Error("content不能为空");
                return;
            }

            if (wxMsg.msg_type == 1)
            {
                SendMsg.SendMarkDownMsg(wxMsg);
            }
            else
            {
                SendMsg.SendTextMsg(wxMsg);
            }
        }
    }
}
